package com.site_assembly.common;

import com.site_assembly.service.ISiteService;
import io.jsonwebtoken.Claims;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Component
public class GetIdUtil {

    @Resource
    private HttpServletRequest request;

    @Resource
    private JWTHelper jwtHelper;

    @Resource
    private ISiteService siteService;

    public Integer getId(){
        String token = request.getHeader("auth_token");
        Claims claims = jwtHelper.parseJWT(token);
        Integer userId = (Integer)claims.get("param");

        Integer siteId= siteService.getSiteIdByUserId(userId);
        return  siteId;

    }


}
